/**
 * Copyright (c) 2011 ~ 2013 Deepin, Inc.
 *               2011 ~ 2013 jouyouyun
 *
 * Author:      jouyouyun <jouyouwen717@gmail.com>
 * Maintainer:  jouyouyun <jouyouwen717@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 **/

package main

import (
	"dlib"
	"dlib/gio-2.0"
	"fmt"
)

const (
	_TEST_SCHEMA_ID   = "com.deepin.daemon.Test"
	_TEST_SCHEMA_PATH = "/com/deepin/daemon/profiles/"
)

func SetGSetings(gs *gio.Settings, name, shortcut, action string) {
	if !gs.SetString("name", name) {
		fmt.Println("Set GSettings Key Failed: name")
		return
	}

	if !gs.SetString("shortcut", shortcut) {
		fmt.Println("Set GSettings Key Failed: shortcut")
		return
	}

	if !gs.SetString("action", action) {
		fmt.Println("Set GSettings Key Failed: action")
		return
	}

	gio.SettingsSync()
}

func PrintGSettings(gs *gio.Settings) {
	fmt.Println(gs.GetString("name"))
	fmt.Println(gs.GetString("shortcut"))
	fmt.Println(gs.GetString("action"))
}

func ResetGSettings(gs *gio.Settings) {
	gs.Reset("name")
	gs.Reset("action")
	gs.Reset("shortcut")
}

func main() {
	gst := gio.NewSettingsWithPath("com.deepin.daemon", "/com/deepin/daemon/Test0")
	PrintGSettings(gst)
	ResetGSettings(gst)
	gio.SettingsSync ()
	return
	gs0 := gio.NewSettingsWithPath(_TEST_SCHEMA_ID, _TEST_SCHEMA_PATH+"Test0/")
	gs0.Connect("changed", func(s *gio.Settings, name string) {
		fmt.Println("name:", name)
		fmt.Println("values:", s.GetString(name))
	})
	/*SetGSetings(gs0, "Gedit", "<Ctrl>Y", "gedit")*/
	PrintGSettings(gs0)

	gs1 := gio.NewSettingsWithPath(_TEST_SCHEMA_ID, _TEST_SCHEMA_PATH+"Test1/")
	/*SetGSetings(gs1, "Gvim", "<Ctrl>G", "gvim")*/
	PrintGSettings(gs1)

	gs2 := gio.NewSettings("com.deepin.daemon")
	gs2.Connect("changed", func(s *gio.Settings, name string) {
		fmt.Println("name:", name)
		fmt.Println("values:", s.GetString(name))
	})

	/*ResetGSettings(gs1)*/
	/*ResetGSettings(gs0)*/
	dlib.StartLoop()
}
